package si.assign1.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="product_type_attributes")
@NamedQueries({
    @NamedQuery(name="listProductTypeAttributes",
                query="SELECT pta FROM ProductTypeAttribute pta"),
    @NamedQuery(name="getProductTypeAttributesById",
                query="SELECT pta FROM ProductTypeAttribute pta WHERE pta.id = :id"),
    @NamedQuery(name="getProductTypeAttributesByName",
                query="SELECT pta FROM ProductTypeAttribute pta WHERE pta.name = :name")
})	
public class ProductTypeAttribute 
{
	public ProductTypeAttribute(){}

	/*
	 * Properties
	 */
	
	/*
	 * Set and get id
	 */
	public int getId()
	{	return id;   }
	public void setId(int id)
	{   this.id = id; }
	
	/*
	 * Set and get name
	 */
	public String getName()
	{   return name;   }
	public void setName(String name)
	{   this.name = name;  }
	
	/*
	 * Set and get is_required
	 */
	public char getIsRequired()
	{   return isRequired;  }
	public void setIsRequired(char isRequired)
	{   this.isRequired = isRequired;  }
	
	/*
	 * Set and get product_type
	 */
	public ProductType getProductType()
	{	return productType;  }
	public void setProductType(ProductType productType)	{
		this.productType = productType;
	}
	
	/**
	 * @return product type attribute values
	 */
	public Set<ProductTypeAttributeValue> getProductTypeAttributeValues() {
		return this.productTypeAttributeValues;
	}
	
	/**
	 * @param productTypeAttributeValues product type attribute values to set
	 */
	public void setProductTypeAttributeValues(
			Set<ProductTypeAttributeValue> productTypeAttributeValues) {
		this.productTypeAttributeValues = productTypeAttributeValues;
	}
	
	/**
	 * @param productTypeAttributeValue the value to add
	 */
	public void addProductTypeAttributeValue(
			ProductTypeAttributeValue productTypeAttributeValue) {
		this.productTypeAttributeValues.add(productTypeAttributeValue);
		productTypeAttributeValue.setProductTypeAttribute(this);
	}
	
	/**
	 * @param productTypeAttributeValue the value to remove
	 */
	public void removeProductTypeAttributeValue(
			ProductTypeAttributeValue productTypeAttributeValue) {
		this.productTypeAttributeValues.remove(productTypeAttributeValue);
		productTypeAttributeValue.setProductTypeAttribute(null);
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Basic(optional=false)
	@Column(name="id", nullable=false)
	private int id;
	@Column(name="name", length=255, nullable=false)
	private String name;
	@Column(name="is_required", length=1, nullable=false)
	private char isRequired;
	
	/*
	 * Many-to-one mapping from ProductTypeAttribute to Product
	 */
	@ManyToOne(optional=false, fetch=FetchType.LAZY, cascade=CascadeType.ALL)
	@JoinColumn(name="product_type_id", nullable=true)
	private ProductType productType;
	
	/*
	 * One-to-many mapping from ProductTypeAttribute to ProductTypeAttributeValue
	 */
	@OneToMany(mappedBy="productTypeAttribute")
	private Set<ProductTypeAttributeValue> productTypeAttributeValues 
		= new HashSet<ProductTypeAttributeValue>();
}
